package com.vhr.service.impl;

import com.vhr.entities.Account;
import com.vhr.entities.AccountExample;
import com.vhr.mapper.AccountMapper;
import com.vhr.mapper.EmployeeMapper;
import com.vhr.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    public EmployeeMapper employeeMapper;
    @Autowired
    public AccountMapper accountMapper;
//    根据员工编号查找员工
    @Override
    public Account selectEmployeeByEmpNum(int empNum) {
        AccountExample example = new AccountExample();
        AccountExample.Criteria criteria = example.createCriteria();
        criteria.andEmpNumEqualTo(empNum);
        return accountMapper.selectByExample(example).get(0);
    }

//    根据员工id查找
    @Override
    public Account selectEmployeeByEmpId(Integer empId) {
        AccountExample example = new AccountExample();
        AccountExample.Criteria criteria = example.createCriteria();
        criteria.andEmpIdEqualTo(empId);
        List<Account> list = accountMapper.selectByExample(example);
        if(list.size() != 0)
            return list.get(0);
        else
            return null;
    }

}
